package org.emet.dao.ash;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.emet.entity.ash.AshItem;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.service.dto.ash.AshItemSearchCriteria;
import org.springframework.stereotype.Repository;

@Repository
public class AshItemDao extends ArchDataSourceBaseDao<AshItem, Long> {

	public List<AshItem> search(AshItemSearchCriteria criteria) {
		String hql = "from AshItem where 1=1 ";
		Map<String, Object> params = new HashMap<String, Object>();
		if (!StringUtils.isBlank(criteria.getCode())) {
			hql += " and code = :code ";
			params.put("code", criteria.getCode());
		}

		if (criteria.getHallId() != -1) {
			hql += " and frame.ashHall.id = :hallId";
			params.put("hallId", criteria.getHallId());
		}

		if (criteria.getFrameId() != -1) {
			hql += " and frame.id = :frameId";
			params.put("frameId", criteria.getFrameId());
		}

		return find(hql, params);

	}

}
